﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using PhotoGallery.Core.Business;
using PhotoGallery.Models.DataContracts;
using System.Collections;
using PhotoGallery.Models.Model.Home;
using System.Web;
using System.Text.RegularExpressions;
using System.IO;
using System.Drawing;
using PhotoGallery.Infrastructure;
using PhotoGallery.Infrastructure.Helpers;


namespace PhotoGallery.Modules.Home.Controllers
{
    public class HomeController : Controller
    {
        #region Field & Property

        private delegate JsonResult Operate(FileNodeOperationDateContract data);

        private Dictionary<string, Operate> operations;

        #endregion

        #region Constructor

        public HomeController()
        {
            this.operations = new Dictionary<string, Operate>();

            this.operations.Add(OperationType.get_children.ToString(), GetChildren);
            this.operations.Add(OperationType.create_node.ToString(), CreateNode);
            this.operations.Add(OperationType.remove_node.ToString(), RemoveNode);
            this.operations.Add(OperationType.rename_node.ToString(), ReNameNode);
            //this.operations.Add(OperationType.move_node.ToString(), MoveNode);
        }

        #endregion

        [AcceptVerbs(HttpVerbs.Get | HttpVerbs.Post)]
        [LoginFilterAttribute(Order = 0)]
        [SecurityFilterAttribute(Order = 1)]
        public ActionResult Index()
        {
            if (TempData["HintMessage"] != null)
            {
                ViewData["HintMessage"] = TempData["HintMessage"];
            }
            return View();
        }

        [AcceptVerbs(HttpVerbs.Get | HttpVerbs.Post)]
        [LoginFilterAttribute(Order = 0)]
        [SecurityFilterAttribute(Order = 1)]
        public ActionResult Detail(int? id)
        {
            if (id == null || !id.HasValue)
                throw new ArgumentException("the id is null!!!!");

            PicNode node = PicNode.Load(id.Value);
            if (node == null)
            {
                TempData["HintMessage"] = new PhotoGallery.Infrastructure.Helpers.HintMessage { Content = "操作失败，系统发生了一个错误" };
                return RedirectToAction("Index");
            }

            FolderDesc desc = FolderDesc.Load(id.Value);

            HomeDetailModel model = new HomeDetailModel(node, desc);

            return View(model);
        }

        [AcceptVerbs(HttpVerbs.Get | HttpVerbs.Post)]
        [LoginFilterAttribute(Order = 0)]
        [SecurityFilterAttribute(Order = 1)]
        public ActionResult Upload(int? id)
        {

            StringBuilder returnvalue = new StringBuilder();

            HttpPostedFileBase img = null;
            if (Request.Files == null || Request.Files.Count == 0)
            {
                return Content("{success: false, status:'fail',message:'请选择文件后再上传!'}", "text/html");
            }


            img = Request.Files[0];

            string imgExtention = CY.Utility.Common.FileUtility.GetFileExtension(img.FileName);
            string imgName = CY.Utility.Common.FileUtility.GetFileName(img.FileName);

            Regex reg = new Regex(@"(?<name>.*)\.(jpe?g|gif|bmp|png)$", RegexOptions.IgnoreCase);

            if (!reg.IsMatch(imgExtention))
                return Content("{success: false, status:'fail',message:'请选择正确的文件!'}", "text/html");


            PicNode node = PicNode.Load(id.Value);



            if (node == null)
                return Content("{success: false, status:'fail',message:'请选择正确的文件夹!'}", "text/html");

            DirectoryInfo dir = new DirectoryInfo(FileConfiguration.FullPath + node.Path.Replace("/", @"\"));

            if (!dir.Exists)
                dir.Create();


            string fileName = imgName + DateTime.Now.ToString("yyyyMMddHHmmss") + DateTime.Now.Millisecond.ToString();

            img.SaveAs(dir.FullName + "\\" + fileName + imgExtention);

            CompactImg(dir.FullName + "\\", FileConfiguration.TmpRoots.FullName + "\\", fileName, imgExtention);

            returnvalue.Append("{success:true,");
            returnvalue.Append(string.Format("imgPath:\"{0}\"", fileName + imgExtention));
            returnvalue.Append(string.Format(",name:'{0}'", fileName + imgExtention));
            returnvalue.Append(string.Format(",message:'{0}'", "上传图片操作成功"));
            returnvalue.Append("}");

            return Content(returnvalue.ToString());
        }


        [AcceptVerbs(HttpVerbs.Get | HttpVerbs.Post)]
        [LoginFilterAttribute(Order = 0)]
        [SecurityFilterAttribute(Order = 1)]
        public JsonResult Delete(int? id)
        {
            PicNode node = null;
            if (id == null || !id.HasValue || (node = PicNode.Load(id.Value)) == null)
                return Json(new { success = false, message = "请选择要进行操作的文件夹！", status = "false" });
            string strImgName = string.Empty;
            if (CY.Utility.Common.RequestUtility.IsGet)
                strImgName = CY.Utility.Common.RequestUtility.GetQueryString("name");
            else
                strImgName = CY.Utility.Common.RequestUtility.GetFormString("name");
            string fileName = CY.Utility.Common.FileUtility.GetFileName(strImgName);
            string fileExtention = CY.Utility.Common.FileUtility.GetFileExtension(strImgName);
            string dirBase = FileConfiguration.Roots.FullName + "\\" + node.Path.Replace("/", "\\");
            string filePath = dirBase + "\\" + fileName + fileExtention;

            if (!System.IO.File.Exists(filePath))
            {
                return Json(new { success = false, message = "不存在该文件！", status = "faile" });
            }

            // 转换为数据库删除
            //System.IO.File.Delete(filePath);

            FileRecord record = new FileRecord();
            record.Path = node.Path + "/" + fileName + fileExtention;
            record.Name = fileName;
            record.Extention = fileExtention;
            record.Save();

            string tempdir = FileConfiguration.TmpRoots.FullName + "\\";

            string bImgName = tempdir + fileName + "_big" + fileExtention;
            string mImgName = tempdir + fileName + "_middle" + fileExtention;
            string sImgName = tempdir + fileName + "_small" + fileExtention;

            System.IO.File.Delete(bImgName);
            System.IO.File.Delete(mImgName);
            System.IO.File.Delete(sImgName);

            return Json(new { success = true, message = "成功将文件删除！！" }, JsonRequestBehavior.AllowGet);

        }

        [AcceptVerbs(HttpVerbs.Get | HttpVerbs.Post)]
        [LoginFilterAttribute()]
        public ActionResult Image(int? id)
        {
            StreamReader reader = null;

            byte[] buffer = null;
            Stream stream = null;

            PicNode node = PicNode.Load(id.Value);

            string fileName = string.Empty;
            string type = string.Empty;

            if (CY.Utility.Common.RequestUtility.IsGet)
            {
                fileName = CY.Utility.Common.RequestUtility.GetQueryString("name");
                type = CY.Utility.Common.RequestUtility.GetQueryString("type");
            }
            else if (CY.Utility.Common.RequestUtility.IsPost)
            {
                fileName = CY.Utility.Common.RequestUtility.GetFormString("name");
                type = CY.Utility.Common.RequestUtility.GetQueryString("type");
            }

            if (string.IsNullOrEmpty(type))
                type = "small";

            string imgName = CY.Utility.Common.FileUtility.GetFileName(fileName);
            string imgExtention = CY.Utility.Common.FileUtility.GetFileExtension(fileName);

            // 临时文件夹目录
            DirectoryInfo dir = new DirectoryInfo(FileConfiguration.TmpRoots.FullName + "\\");

            if (System.IO.File.Exists(dir + imgName + "_" + type + imgExtention))
            {
                reader = new StreamReader(dir.FullName + imgName + "_" + type + imgExtention);
            }
            else
            {
                DirectoryInfo newdir = new DirectoryInfo(FileConfiguration.FullPath + node.Path.Replace("/", @"\"));

                if (!dir.Exists)
                    dir.Create();

                CompactImg(newdir.FullName + "\\", FileConfiguration.TmpRoots.FullName + "\\", imgName, imgExtention);

                reader = new StreamReader(dir.FullName + imgName + "_" + type + imgExtention);
            }
            if (reader != null)
            {
                buffer = new byte[reader.BaseStream.Length];
                reader.BaseStream.Read(buffer, 0, Convert.ToInt32(reader.BaseStream.Length));
                reader.Close();
            }


            if (buffer == null)
            {
                buffer = new byte[1];
            }

            HttpContext.Response.ContentType = "application/octet-stream";
            HttpContext.Response.BinaryWrite(buffer);

            return View();

        }

        [AcceptVerbs(HttpVerbs.Get | HttpVerbs.Post)]
        [LoginFilterAttribute(Order = 0)]
        [SecurityFilterAttribute(Order = 1)]
        public ActionResult DownLoad(int? id)
        {
            StreamReader reader = null;

            PicNode node = PicNode.Load(id.Value);

            string fileName = string.Empty;


            if (CY.Utility.Common.RequestUtility.IsGet)
            {
                fileName = CY.Utility.Common.RequestUtility.GetQueryString("name");

            }
            else if (CY.Utility.Common.RequestUtility.IsPost)
            {
                fileName = CY.Utility.Common.RequestUtility.GetFormString("name");

            }


            string imgName = CY.Utility.Common.FileUtility.GetFileName(fileName);
            string imgExtention = CY.Utility.Common.FileUtility.GetFileExtension(fileName);

            // 临时文件夹目录
            DirectoryInfo dir = new DirectoryInfo(FileConfiguration.Roots.FullName + "\\" + node.Path.Replace("/", "\\"));

            if (System.IO.File.Exists(dir.FullName + "\\" + imgName + imgExtention))
            {

                System.Web.HttpContext.Current.Response.Clear();
                System.Web.HttpContext.Current.Response.Charset = "UTF-8";
                System.Web.HttpContext.Current.Response.Buffer = true;
                System.Web.HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8;
                System.Web.HttpContext.Current.Response.HeaderEncoding = System.Text.Encoding.UTF8;
                HttpBrowserCapabilities br = System.Web.HttpContext.Current.Request.Browser;
                string strTemp = imgName + imgExtention;  //System.Web.HttpUtility.UrlEncode(filename, System.Text.Encoding.UTF8);/

                byte[] buffer = new byte[100000];
                int iLength;
                long dataToRead;
                System.IO.Stream iStream = new FileStream(dir.FullName + "\\" + imgName + imgExtention, FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read);
                dataToRead = iStream.Length;

                System.Web.HttpContext.Current.Response.ContentType = "application/octet-stream";

                if (br.Browser == "IE")
                {
                    strTemp = HttpUtility.UrlEncode(strTemp);

                    strTemp = strTemp.Replace("+", "%20");
                    System.Web.HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + strTemp);
                }
                else
                {
                    strTemp = strTemp.Replace(" ", "");
                    System.Web.HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment; filename=" + strTemp);

                }
                while (dataToRead > 0)
                {
                    if (System.Web.HttpContext.Current.Response.IsClientConnected)
                    {
                        iLength = iStream.Read(buffer, 0, 100000);
                        System.Web.HttpContext.Current.Response.BinaryWrite(buffer);
                        System.Web.HttpContext.Current.Response.Flush();
                        buffer = new byte[100000];
                        dataToRead = dataToRead - iLength;
                    }
                    else
                    {
                        dataToRead = -1;
                    }
                }





            }




            return View();
        }

        [AcceptVerbs(HttpVerbs.Get | HttpVerbs.Post)]
        [LoginFilterAttribute()]
        public ActionResult Add()
        {

            return View();
        }


        /// <summary>
        /// 搜索文件
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [AcceptVerbs(HttpVerbs.Get | HttpVerbs.Post)]
        [LoginFilterAttribute(Order = 0)]
        [SecurityFilterAttribute(Order = 1)]
        public ActionResult Search(FolderSearchModel model, int? id)
        {

            if (model == null)
                model = new FolderSearchModel();

            if (model.Search == null)
                model.Search = new FolderSearch();
            model.Search.Status = (int?)0;
            if (id != null && id.HasValue)
                model.Search.Id = id.Value;

            model = PicNode.Search(model.Search);

            ViewData["EventInfo"] = EventInfo.GetAllOrder().ToList();

            return View(model);
        }

        [AcceptVerbs(HttpVerbs.Get | HttpVerbs.Post)]
        [LoginFilterAttribute(Order = 0)]
        [SecurityFilterAttribute(Order = 1)]
        public ActionResult Authority(FolderSearchModel model)
        {

            if (model == null)
                model = new FolderSearchModel();
            if (model.Search == null)
                model.Search = new FolderSearch();
            model = PicNode.Search(model.Search);

            ViewData["EventInfo"] = EventInfo.GetAllOrder().ToList();

            return View(model);

        }

        [AcceptVerbs(HttpVerbs.Get | HttpVerbs.Post)]
        [LoginFilterAttribute(Order = 0)]
        [SecurityFilterAttribute(Order = 1)]
        public ActionResult SaveAuthority(int? id)
        {
            PicNode node = null;
            if (id == null || !id.HasValue || (node = PicNode.Load(id.Value)) == null)
                throw new HttpException("id is null !!! or the picnode is null!!!");
            if (node.Status == 1)
            {
                node.Status = 0;
            }
            else
            {
                node.Status = 1;
            }
            node.Save();
            TempData["HintMessage"] = new PhotoGallery.Infrastructure.Helpers.HintMessage { Content = "操作成功！！！" };
            return RedirectToAction("Authority");
        }

        #region 文件树形节点操作

        [AcceptVerbs(HttpVerbs.Get | HttpVerbs.Post)]
        [LoginFilterAttribute()]
        public JsonResult Operation(FileNodeOperationDateContract contract)
        {
            if (ReferenceEquals(contract, null))
                throw new ArgumentNullException("contract is null!!!!");

            if (string.IsNullOrEmpty(contract.Operation)) throw new ArgumentException("the operation contained is null or empty!!!");

            if (operations[contract.Operation] == null) throw new ArgumentException("the operation is not exist!!!");

            return this.operations[contract.Operation](contract);

        }


        /// <summary>
        /// 获取文件夹的子目录
        /// </summary>
        /// <param name="contract"></param>
        /// <returns></returns>
        [AcceptVerbs(HttpVerbs.Get | HttpVerbs.Post)]
        [LoginFilterAttribute()]
        public JsonResult GetChildren(FileNodeOperationDateContract contract)
        {
            if (contract == null)
                throw new ArgumentNullException("the argument is null!!!!!");

            IList<PicNode> nodes = new List<PicNode>();

            IList<Node> results = new List<Node>();

            if (contract.Id == null || !contract.Id.HasValue)
            {
                nodes = PicNode.GetRoots().ToList();
            }
            else
            {
                nodes = PicNode.GetSubs(contract.Id.Value).ToList();
            }

            foreach (var n in nodes)
            {
                results.Add(new Node(n.Name, n.Id.ToString()));
            }

            return Json(results, JsonRequestBehavior.AllowGet);

        }

        /// <summary>
        /// 创建文件目录
        /// </summary>
        /// <param name="contract"></param>
        /// <returns></returns>
        [AcceptVerbs(HttpVerbs.Get | HttpVerbs.Post)]
        [LoginFilterAttribute()]
        public JsonResult CreateNode(FileNodeOperationDateContract contract)
        {
            if (contract == null)
                throw new ArgumentNullException("the argument is null!!!!!");

            PicNode parent = PicNode.Load(contract.ParentId.Value);

            if (parent == null)
                throw new ArgumentException("the parentid is null!!!!");

            PicNode temp = PicNode.FindByPath(parent.Path + "/" + contract.Name);

            if (temp != null)
                return Json(new { status = 0, success = false, message = "请确定文件夹名称在该目录下是否唯一！" });

            PicNode node = new PicNode();
            node.IsFile = false;
            node.Status = 0;
            node.Root = parent.Root;
            node.Name = contract.Name;
            node.Path = parent.Path + "/" + node.Name;
            PicNode.Insert(node);
            return Json(new { id = node.Id.ToString(), status = node.Status.ToString(), success = true, message = "成功创建文件夹！" });
        }


        [AcceptVerbs(HttpVerbs.Get | HttpVerbs.Post)]
        [LoginFilterAttribute()]
        public JsonResult ReNameNode(FileNodeOperationDateContract contract)
        {
            if (contract == null)
                throw new ArgumentNullException("the argument is null!!!!!");

            PicNode node = PicNode.Load(contract.Id.Value);
            node.Name = contract.Name;
            node.Save();

            return Json(new { id = node.Id, status = 1, success = true, message = "成功将文件夹重新命名！" });
        }


        [AcceptVerbs(HttpVerbs.Get | HttpVerbs.Post)]
        [LoginFilterAttribute()]
        public JsonResult RemoveNode(FileNodeOperationDateContract contract)
        {
            if (contract == null)
                throw new ArgumentNullException("the argument is null!!!!!");

            //  修改 
            IList<PicNode> roots = PicNode.GetRoots().ToList();

            bool isdelete = true;

            if (roots.Count == 1 && contract.Id == roots[0].Id)
            {
                isdelete = false;
                return Json(new { id = contract.Id.ToString(), status = 0, success = false, message = "该文件夹是根目录不能删除！" });
            }

            if (isdelete)
            {
                PicNode.Delete(contract.Id.Value);
            }

            return Json(new { id = contract.Id.ToString(), status = 1, success = true, message = "成功将文件夹移除！" });

        }



        /*
                [AcceptVerbs(HttpVerbs.Post | HttpVerbs.Get)]
                public JsonResult MoveNode(FileNodeOperationDateContract contract)
                {
                    if (contract == null)
                        throw new ArgumentNullException("the argument is null!!!!!");


                    return Json(new { id = role.Key, status = role.Status.ToString() });
                }
        */

        #endregion


        #region 编辑文件附加信息

        /// <summary>
        /// 编辑文件的附加信息
        /// </summary>
        /// <param name="id">文件夹的ID</param>
        /// <returns></returns>
        [AcceptVerbs(HttpVerbs.Get | HttpVerbs.Post)]
        [LoginFilterAttribute(Order = 0)]
        [SecurityFilterAttribute(Order = 1)]
        public ActionResult Edit(int? id)
        {
            if (id == null || !id.HasValue)
                throw new ArgumentException(" the id is empty!! idiot!!");

            FolderDesc desc = FolderDesc.Load(id.Value);



            ViewData["EventInfo"] = EventInfo.GetAllOrder().ToList();

            IList<SelectListItem> leaders = Leader.GetAllLeader().ToList().ToSelectList(item => item.Name, item => item.Name);

            if (desc != null && !string.IsNullOrEmpty(desc.Leader))
            {
                IList<string> selected = desc.Leader.Split(',').ToList();

                foreach (var s in selected)
                {
                    foreach (var i in leaders)
                    {
                        if (s.Equals(i.Value))
                            i.Selected = true;
                    }
                }
            }

            ViewData["Leader"] = leaders;

            return View(desc == null ? new FolderDesc(id.Value) : desc);
        }
        [AcceptVerbs(HttpVerbs.Get | HttpVerbs.Post)]
        [LoginFilterAttribute(Order = 0)]
        [SecurityFilterAttribute(Order = 1)]
        public ActionResult Save(FolderDesc model)
        {
            if (model == null)
            {
                TempData["HintMessage"] = new PhotoGallery.Infrastructure.Helpers.HintMessage { Content = "操作失败，系统发生了一个错误" };
                return RedirectToAction("Index");
            }

            FolderDesc oringe = FolderDesc.Load(model.Id);
            PicNode node = PicNode.Load(model.Id);
            if (oringe != null)
            {
                oringe.KeyWord = model.KeyWord;
                oringe.Photographer = model.Photographer;
                oringe.StartDate = model.StartDate;
                oringe.EndDate = model.EndDate;
                //if (!string.IsNullOrEmpty(model.Leader))
                // oringe.Leader = model.Leader;

                oringe.Leader = Request.Form["LeaderInfo"];
                oringe.OtherLeader = model.OtherLeader;
                oringe.Guest = model.Guest;
                if (!string.IsNullOrEmpty(model.InnerLocation))
                    oringe.InnerLocation = model.InnerLocation;
                oringe.OuterLocation = model.OuterLocation;
                if (model.EventInfo != 0)
                {
                    oringe.EventInfo = model.EventInfo;
                }
                oringe.EventDesc = model.EventDesc;
                oringe.Save();
            }
            else
            {
                model.Save();
            }


            TempData["HintMessage"] = new PhotoGallery.Infrastructure.Helpers.HintMessage { Content = string.Format("为文件夹({0})添加描述信息成功", node != null ? node.Name : string.Empty) };

            return RedirectToAction("Index");
        }




        #endregion


        #region Class Helper

        private IList<PicNode> GetSubs(PicNode picNode)
        {
            try
            {
                if (picNode == null)
                    throw new NullReferenceException("picNode for picking up sub node is null!!!");
                return PicNode.GetSubs(picNode).ToList();
            }
            catch (Exception ex)
            {
                throw ex;
            }

        }

        private PicNode GetNode(int? nodeId)
        {
            PicNode node = null;
            if (nodeId == null)
                node = PicNode.getRoot();
            else
                node = PicNode.Load(nodeId.Value);
            return node;
        }


        #endregion


        #region Json
        [AcceptVerbs(HttpVerbs.Get | HttpVerbs.Post)]
        [LoginFilterAttribute()]
        public JsonResult SearchLocation()
        {
            string s = Request.QueryString["s"];

            if (string.IsNullOrEmpty(s))
                throw new ArgumentException("the query is null !!!");

            IList<Location> locations = Location.Search(s).ToList();

            var descs = new ArrayList();

            if (locations != null)
            {
                foreach (var item in locations)
                {
                    descs.Add(new { id = item.Id, name = item.Name });
                }
            }
            return Json(new { success = true, list = descs }, JsonRequestBehavior.AllowGet);
        }

        [AcceptVerbs(HttpVerbs.Get | HttpVerbs.Post)]
        [LoginFilterAttribute()]
        public JsonResult SearchLeader()
        {
            string s = Request.QueryString["s"];

            if (string.IsNullOrEmpty(s))
                throw new ArgumentException("the querystring is null or enpty !");

            IList<Core.Business.Leader> leaders = Core.Business.Leader.Search(s).ToList();


            var result = new ArrayList();

            if (leaders != null)
            {

                foreach (var item in leaders)
                {
                    result.Add(new { id = item.Id, name = item.Name });
                }
            }

            return Json(new { success = true, list = result }, JsonRequestBehavior.AllowGet);
        }
        #endregion


        private string[] CompactImg(string appPath, string tempPath, string imgName, string imgExtention)
        {
            string bImgName = tempPath + imgName + "_big" + imgExtention;
            string mImgName = tempPath + imgName + "_middle" + imgExtention;
            string sImgName = tempPath + imgName + "_small" + imgExtention;

            if (System.IO.File.Exists(appPath + imgName + imgExtention))
            {
                Bitmap bmp = new Bitmap(appPath + imgName + imgExtention);
                int width = bmp.Width;
                int height = bmp.Height;
                bmp.Dispose();

                if (height < width)
                {
                    height = Convert.ToInt32(width > 600 ? (600f / width) * height : height);
                    width = 600;
                }
                else
                {
                    width = Convert.ToInt32(height > 600 ? (600f / height) * width : width);
                    height = 600;
                }


                string originalImag = appPath + imgName + imgExtention;

                // 将图片压缩为大缩略图
                using (StreamReader reader = new StreamReader(appPath + imgName + imgExtention))
                {
                    CY.Utility.Common.ImageUtility.ThumbAsJPG(reader.BaseStream, bImgName, width, height);
                }

                if (height < width)
                {
                    height = Convert.ToInt32(width > 300 ? (300f / width) * height : height);
                    width = 300;
                }
                else
                {
                    width = Convert.ToInt32(height > 300 ? (300f / height) * width : height);
                    height = 300;
                }

                // 将大图片压缩为中等缩略图
                using (StreamReader reader = new StreamReader(appPath + imgName + imgExtention))
                {
                    CY.Utility.Common.ImageUtility.ThumbAsJPG(reader.BaseStream, mImgName, width, height);
                }

                if (height < width)
                {
                    height = Convert.ToInt32(width > 100 ? (100f / width) * height : height);
                    width = 100;
                }
                else
                {
                    width = Convert.ToInt32(height > 100 ? (100f / height) * width : height);
                    height = 100;
                }

                // 生成小头像
                using (StreamReader reader = new StreamReader(appPath + imgName + imgExtention))
                {
                    CY.Utility.Common.ImageUtility.ThumbAsJPG(reader.BaseStream, sImgName, 120, 100);
                }

                //try
                //{
                //    File.Delete(appPath + imgName + imgExtention);
                //}
                //catch
                //{
                //    ;
                //}

                return new string[] { bImgName, mImgName, sImgName };

            }
            else
            {
                return new string[] { };
            }

        }

    }

    internal enum OperationType
    {
        get_children,
        create_node,
        remove_node,
        rename_node,
        move_node,


    }

}
